<template>
  <view 
    v-if="showBubble && bubbleText" 
    class="bubble"
    :class="bubbleType"
    :style="bubblePosition"
    id="speech-bubble"
  >
    <text class="bubble-text">{{ bubbleText }}</text>
  </view>
</template>

<script>
export default {
  name: 'PetBubble',
  props: {
    showBubble: {
      type: Boolean,
      default: false
    },
    bubbleText: {
      type: String,
      default: ''
    },
    bubbleType: {
      type: String,
      default: 'normal'
    },
    petPosition: {
      type: Object,
      default: () => ({ left: '50%', top: '50%' })
    }
  },
  computed: {
    bubblePosition() {
      // 计算气泡相对于宠物的位置
      return {
        left: this.petPosition.left,
        top: `calc(${this.petPosition.top} - 100rpx)`,
        transform: 'translateX(-50%)'
      }
    }
  }
}
</script>

<style scoped>
/* 交互气泡 */
.bubble {
  position: fixed;
  background: #fff;
  color: #333;
  padding: 16rpx 20rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
  white-space: nowrap;
  max-width: 300rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
  z-index: 999997;
  animation: bubbleAppear 0.3s ease-out;
  border: 2rpx solid #e0e0e0;
  backdrop-filter: blur(10rpx);
}

.bubble-text {
  display: block;
  line-height: 1.4;
  word-break: break-all;
  font-weight: 500;
}

/* 气泡类型样式 */
.normal {
  background: #fff;
  color: #333;
  border-color: #e0e0e0;
}

.happy {
  background: #e8f5e8;
  color: #2e7d32;
  border-color: #4caf50;
}

.sad {
  background: #ffebee;
  color: #c62828;
  border-color: #f44336;
}

.hungry {
  background: #fff3e0;
  color: #ef6c00;
  border-color: #ff9800;
}

.tired {
  background: #e3f2fd;
  color: #1565c0;
  border-color: #2196f3;
}

.confused {
  background: #f3e5f5;
  color: #7b1fa2;
  border-color: #9c27b0;
}

.listening {
  background: #e0f2f1;
  color: #00695c;
  border-color: #00bcd4;
}

@keyframes bubbleAppear {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.8) translateY(10rpx);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
  }
}

/* 响应式调整 */
@media screen and (max-width: 750rpx) {
  .bubble {
    font-size: 22rpx;
    padding: 12rpx 16rpx;
    max-width: 250rpx;
  }
}
</style>
